from common.base.base_handler import BaseHandler
from services.ocb.model import Ocb
from services.ocb.schemas.ocb_registers import OcbThresholds, OcbCurrents28v, OcbStates
from settings import settings


class OcbHandler(BaseHandler):
    __slots__ = ['model']

    async def handle_set_ocb_threshold(self, params: dict) -> bool:
        name, value = params['name'], params['value']
        self.model.write_threshold(name, value)

        return True

    async def handle_get_all_ocb_thresholds(self) -> OcbThresholds:
        return self.model.ocb_thresholds

    async def handle_get_ocb_threshold(self, params: dict) -> float:
        name = params['name']
        return self.model.read_threshold(name)

    async def handle_get_all_ocb_current_28v(self) -> OcbCurrents28v:
        return self.model.ocb_currents_28v

    async def handle_get_all_ocb_states(self) -> OcbStates:
        return self.model.ocb_states

    async def handle_read_services_ocb(self) -> list[bool]:
        return self.model.read_services_ocb()

    async def handle_get_ocb_in_work_state(self) -> list[bool]:
        return self.model.ocb_in_work

    def __init__(self) -> None:
        self.model = Ocb()

        super(OcbHandler, self).__init__(request_queue_uuid=settings.OCB_REQUEST_QUEUE)

        self.handle('get_all_ocb_states', self.handle_get_all_ocb_states)
        self.handle('set_ocb_threshold', self.handle_set_ocb_threshold)
        self.handle('get_all_ocb_thresholds', self.handle_get_all_ocb_thresholds)
        self.handle('get_ocb_threshold', self.handle_get_ocb_threshold)
        self.handle('get_all_ocb_current_28v', self.handle_get_all_ocb_current_28v)
        self.handle('read_services_ocb', self.handle_read_services_ocb)
        self.handle('get_ocb_in_work_state', self.handle_get_ocb_in_work_state)
